//
//  SynDetailsThridCell.m
//  XDBaseFrameWork
//
//  Created by XD-XY on 10/20/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "SynDetailsThridCell.h"
#import "Detail.h"
@implementation SynDetailsThridCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self makeViews];
    }
    return self;
}

-(void)makeViews
{
    self.backgroundColor = [UIColor whiteColor];
    
    UIView * bgbg1 = [UIView initViewRect:CGRectMake(0, 0, UI_SCREEN_WIDTH, 80) andBackGroudColor:[UIColor whiteColor]];
    [bg1 addSubview:bgbg1];
    
    redHeart = [[UIImageView alloc] initWithFrame:CGRectMake(UI_SCREEN_WIDTH-37, 40, 22, 20)];
    redHeart.image = [UIImage imageNamed:@"nocollection@2x"];
    [bgbg1 addSubview:redHeart];
    
    favNumberLB = [UILabel initLabelText:@"" andRect:CGRectMake(UI_SCREEN_WIDTH-42, height_y(redHeart)-2, 32, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:UIColorFromRGB(0xff6000) andTextAlignment:NSTextAlignmentCenter];
    [bgbg1 addSubview:favNumberLB];
    
    collcetionbtn = [UIButton initButton:CGRectMake(UI_SCREEN_WIDTH-55, 22+8, 55, 44) btnNorImage:nil btnHighlightImage:nil btnTitle:nil titleColor:nil titleFont:nil];
    [collcetionbtn addTarget:self action:@selector(collectCameraMan:) forControlEvents:UIControlEventTouchUpInside];
    [bgbg1 addSubview:collcetionbtn];
    
    headIV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 66, 66)];
    headIV.backgroundColor = UIColorFromRGB(0xeaeaea);
    headIV.layer.masksToBounds = YES;
    headIV.layer.cornerRadius = 33;
    headIV.userInteractionEnabled = YES;
    [bgbg1 addSubview:headIV];
    
    UITapGestureRecognizer *tapHeadIV = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headIVTaped)];
    tapHeadIV.numberOfTapsRequired = 1;
    [headIV addGestureRecognizer:tapHeadIV];
    
    
    nameLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(headIV)+12.5f, 10, 80, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:nameLB];
    
    if (_isRenZheng) {
        renzhengIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"renzheng"]];
        renzhengIV.frame = CGRectMake(VIEW_POINT_MAX_X(nameLB), 12, 0, 0);
        [bgbg1 addSubview:renzhengIV];
    }
    
    jibieLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(nameLB), height_y(nameLB)-10, 140, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:RGBA(122, 110, 99, 1) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:jibieLB];
    
//    UILabel * qiLB = [UILabel initLabelText:@"起" andRect:CGRectMake(UI_SCREEN_WIDTH-22, 22, 16, 16) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:11] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
//    [bgbg1 addSubview:qiLB];
    
//    priceLB = [UILabel initLabelText:@"" andRect:CGRectMake(nameLB.frame.origin.x, height_y(nameLB), 100, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:18] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
//    priceLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[@"0"] Color:RGBA(255, 116, 106, 1) Font:[UIFont systemFontOfSize:15] AllText:priceLB.text];
//    [bgbg1 addSubview:priceLB];
    
    normalPriceLB = [UILabel initLabelText:@"" andRect:CGRectMake(UI_SCREEN_WIDTH-100, jibieLB.frame.origin.y, 100, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:RGBA(122, 110, 99, 1) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:normalPriceLB];
    
    numberLB = [UILabel initLabelText:@"" andRect:CGRectMake(nameLB.frame.origin.x, height_y(jibieLB), 100, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0xff6000) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:numberLB];
    
//    distanceLB = [UILabel initLabelText:@"" andRect:CGRectMake(priceLB.frame.origin.x, 95, 150, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:RGBA(122, 110, 99, 1) andTextAlignment:NSTextAlignmentLeft];
//    [bgbg1 addSubview:distanceLB];
    
//    line = [UIView initViewRect:CGRectMake(UI_SCREEN_WIDTH-6, normalPriceLB.frame.origin.y+3, 25, 1) andBackGroudColor:UIColorFromRGB(0x828282)];
//    [bgbg1 addSubview:line];
    
    
    jibieIV = [[UIImageView alloc] initWithFrame:CGRectMake(UI_SCREEN_WIDTH-10-60, 10, 60, 12)];
    jibieIV.image = LOADIMAGE(@"seller-1-5@2x");
    [bgbg1 addSubview:jibieIV];
    
    UIImageView * shortXuXian = [[UIImageView alloc] initWithFrame:CGRectMake(85, height_y(nameLB)+2, 226, .5f)];
    shortXuXian.image = [UIImage imageNamed:@"xuxian_short"];
    [bgbg1 addSubview:shortXuXian];
    
    
    scoreLB = [UILabel initLabelText:@"" andRect:CGRectMake(numberLB.frame.origin.x, height_y(shortXuXian)+3, 180, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:scoreLB];
    
    
    [self.contentView addSubview:bgbg1];
}

-(void)setDataDict:(NSMutableDictionary *)dataDict
{
    if (![[dataDict allKeys] count]){
        return;
    }
    
    if(_dataDict){
        _dataDict = nil;
    }
    
    _dataDict = [[NSMutableDictionary alloc] initWithDictionary:dataDict];
    
    [headIV sd_setImageWithURL:[NSURL URLWithString:_dataDict[@"EmplAvator"]] placeholderImage:LOADIMAGE(@"placeholderHeader@2x")];
    nameLB.text =_dataDict[@"EmplName"];
    jibieLB.text = _dataDict[@"LevelName"];
    distanceLB2.text =_dataDict[@"FWCity"];
    
    
    if ([_dataDict[@"IsCollection"] intValue]==1){
        redHeart.image = LOADIMAGE(@"iscollection@2x");
    }else{
        redHeart.image = LOADIMAGE(@"nocollection@2x");

    }
    
    
//    NSDictionary * adict = @{@"ItemName":@"单量",
//                          @"Avg":_dataDict[@"OrderCount"]};
//    NSDictionary * bdict =@{@"ItemName":@"收藏",
//                            @"Avg":_dataDict[@"CollectionCount"]};
//    
//    Detail * soc1 = (Detail *)[self.contentView viewWithTag:10000];
//    Detail * soc2 = (Detail *)[self.contentView viewWithTag:10001];
//    Detail * soc3 = (Detail *)[self.contentView viewWithTag:10002];
//    Detail * soc4 = (Detail *)[self.contentView viewWithTag:10003];
//    Detail * soc5 = (Detail *)[self.contentView viewWithTag:10004];
//    
//    [soc1 initDataWithDict:[_dataDict[@"ReviewTypeAvg"] firstObject]];
//    [soc2 initDataWithDict:[_dataDict[@"ReviewTypeAvg"] objectAtIndex:1]];
//    [soc3 initDataWithDict:[_dataDict[@"ReviewTypeAvg"] objectAtIndex:2]];
//    [soc4 initDataWithDict:adict];
//    [soc5 initDataWithDict:bdict];
 
    
    [headIV sd_setImageWithURL:[NSURL URLWithString:dataDict[@"EmplAvator"]] placeholderImage:LOADIMAGE(@"placeholderHeader@2x")];
    nameLB.text = dataDict[@"EmplName"];
    [nameLB sizeToFit];
    
    jibieLB.text = [NSString stringWithFormat:@"%@",dataDict[@"LevelName"]];
    jibieLB.frame = CGRectMake(VIEW_POINT_MAX_X(nameLB), nameLB.frame.origin.y+2, 80, 12);
    [jibieLB sizeToFit];
    
    renzhengIV.frame = CGRectMake(VIEW_POINT_MAX_X(jibieLB), 18, 14, 14);
    renzhengIV.hidden = NO;
    
//    priceLB.text = [NSString stringWithFormat:@"￥%@",dataDict[@"LowPrice"]];
//    [priceLB sizeToFit];
//    priceLB.frame=CGRectMake(UI_SCREEN_WIDTH-22-priceLB.bounds.size.width, 16, priceLB.bounds.size.width, priceLB.bounds.size.height);
//    //    priceLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[infoDict[@"LowPrice"]] Color:RGBA(255, 116, 106, 1) Font:[UIFont systemFontOfSize:15] AllText:priceLB.text];
//    
//    normalPriceLB.text = [NSString stringWithFormat:@"市场参考价 %@",dataDict[@"MarketPrice"]];
//    [normalPriceLB sizeToFit];
//    normalPriceLB.frame = CGRectMake(UI_SCREEN_WIDTH-normalPriceLB.bounds.size.width-10, jibieLB.frame.origin.y, normalPriceLB.bounds.size.width, normalPriceLB.bounds.size.height);
    
//    line.frame = CGRectMake(UI_SCREEN_WIDTH-6-[dataDict[@"MarketPrice"] length]*8, normalPriceLB.frame.origin.y+7, [dataDict[@"MarketPrice"] length]*8, 1);
    
    favNumberLB.text = [NSString stringWithFormat:@"%@",dataDict[@"CollectionCount"]];
    numberLB.text = [NSString stringWithFormat:@"共接单%@次",dataDict[@"OrderCount"]];
    numberLB.frame = CGRectMake(nameLB.frame.origin.x, height_y(scoreLB)+3, 120, 15);
    
    distanceLB.text = [NSString stringWithFormat:@"服务范围：%@",dataDict[@"FWCity"]];
    
    
    NSMutableArray * scoreArray = [NSMutableArray arrayWithArray:dataDict[@"ReviewTypeAvg"]];
    if (scoreArray.count > 2) {
        scoreLB.text = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",scoreArray[0][@"ItemName"],scoreArray[0][@"Avg"],scoreArray[1][@"ItemName"],scoreArray[1][@"Avg"],scoreArray[2][@"ItemName"],scoreArray[2][@"Avg"]];
        
    }
    
    NSInteger num = [XDTools changeOrderCountToLevel:[dataDict[@"Score"]integerValue]];
    jibieIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"seller-%d-%d@2x",num/5+1,num%5+1]];
    jibieIV.frame = CGRectMake(UI_SCREEN_WIDTH-10-(num%5+1)*12,12, (num%5+1)*12, 12);
    
//    int num = [dataDict[@"OrderCount"] intValue];
//    if (num >= 250) {
//        num = 249;
//    }else if (!num) {
//        num = 1;
//    }
//    jibieIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"seller-%d-%d@2x",num/50+1,num%50/10+1]];
//    jibieIV.frame = CGRectMake(UI_SCREEN_WIDTH-10-(num%50/10+1)*12, 12, (num%50/10+1)*12, 12);
}

-(void)setIsRenZhen:(BOOL)isRenZhen
{
    _isRenZhen = isRenZhen;
    if (_isRenZhen){
        
        renzhengIV.hidden = NO;
    }else{
        renzhengIV.hidden = YES;
    }
    
    ///计算名字长度
    CGRect rect = [XDTools autoSizeOftext:nameLB.text andSize:CGSizeMake(200,15) andtextFont:16.0f];
    nameLB.frame = CGRectMake(width_x(headIV)+15,7,rect.size.width,5+5+15);
    renzhengIV.frame = CGRectMake(width_x(nameLB)+5, 13.5,14,14);
    jibieLB.frame = CGRectMake(width_x(nameLB)+23,12, 140, 5+11+5);
}

-(void)setIscollcetion:(BOOL)iscollcetion
{
    
    _iscollcetion = iscollcetion;
    if (_iscollcetion){
        redHeart.image = LOADIMAGE(@"iscollection@2x");
    }else{
        redHeart.image = LOADIMAGE(@"nocollection@2x");

    }
    collcetionbtn.userInteractionEnabled = YES;
}

-(void)setCollcetioncount:(int)collcetioncount
{
    _collcetioncount = collcetioncount;
    favNumberLB.text = [NSString stringWithFormat:@"%d",_collcetioncount];

}

-(void)collectCameraMan:(UIButton *)btn
{
    if (_iscollcetion){
        [_delegate collectBtnClick:NO andbtn:btn];
    }else{
        [_delegate collectBtnClick:YES andbtn:btn];
    }
}

-(void)headIVTaped
{
    [_delegate gotoEmplHomeVCWithEmplID:_dataDict[@"EmplID"] andEmplName:_dataDict[@"EmplName"] andEmplImg:headIV.image];
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
